package org.wuzhou.lvyou.view;

import org.wuzhou.lvyou.R;
import org.wuzhou.lvyou.activity.AboutActivity;
import org.wuzhou.lvyou.activity.DirectionActivity;
import org.wuzhou.lvyou.activity.HelperActivity;
import org.wuzhou.lvyou.activity.MainActivity;
import org.wuzhou.lvyou.base.BaseView;
import org.wuzhou.lvyou.map.WebMapActivity;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.view.MotionEvent;

/**
 * 主程序布局类
 * 
 * @author Administrator
 * 
 */
public class MainView extends BaseView {

	private MainActivity father;

	//
	private Bitmap bmp_main_bg;
	private Bitmap bmp_btn_bg;
	private Bitmap bmp_btn_bg1;
	private Bitmap bmp_btn_bg2;
	private Bitmap bmp_btn_bg3;

	private Bitmap bmp_word_helper1;
	private Bitmap bmp_word_helper2;
	private Bitmap bmp_word_helper;
	private Bitmap bmp_word_eixt;

	private Bitmap bmp_word_south;
	private Bitmap bmp_word_south1;
	private Bitmap bmp_word_south2;
	private Bitmap bmp_word_about1;
	private Bitmap bmp_word_about2;
	private Bitmap bmp_word_about;

	private Bitmap bmp_word_guide1;
	private Bitmap bmp_word_guide2;
	private Bitmap bmp_word_guide;

	//
	private RectF rect_main_bg;
	private RectF rect_btn_bg1;
	private RectF rect_btn_bg2;
	private RectF rect_btn_bg3;
	private RectF rect_btn_bg4;
	
	private RectF rect_btn_exit;

	private RectF rect_btn_bg;

	private Bitmap bmp_btn_exit;

	private Bitmap bmp_btn_exit1;

	private Bitmap bmp_btn_exit2;

	private Bitmap bmp_btn_bg4;

	//
	public MainView(MainActivity father) {
		super(father);
		this.father = father;

	}

	@Override
	public void initRect() {
		rect_main_bg = new RectF(0, 0, screenW, screenH);
		rect_btn_bg1 = new RectF((screenW - bmp_btn_bg1.getWidth()) / 2+30,
				screenH / 3 - bmp_btn_bg1.getHeight() / 2-30,
				(screenW + bmp_btn_bg1.getWidth()) / 2-30, screenH / 3
						+ bmp_btn_bg1.getHeight() / 2-60);
		

		
		rect_btn_bg = new RectF((screenW - bmp_btn_bg1.getWidth()) / 2, screenH
				/ 3 - bmp_btn_bg1.getHeight() / 2,
				(screenW + bmp_btn_bg1.getWidth()) / 2, screenH / 3
						+ bmp_btn_bg1.getHeight() / 2);
		
		rect_btn_bg4=new RectF(rect_btn_bg);
		rect_btn_bg4.top+=88;
		rect_btn_bg4.bottom+=50;
		rect_btn_bg4.left+=30;
		rect_btn_bg4.right-=30;
		
		 rect_btn_bg.top += 30;
		rect_btn_bg.left += 30;
		rect_btn_bg.bottom -= 30;
		rect_btn_bg.right -= 30;

		rect_btn_bg2 = new RectF(rect_btn_bg);

		rect_btn_bg2.top = rect_btn_bg1.bottom + 20;
		rect_btn_bg2.left -= 80;
		rect_btn_bg2.bottom = rect_btn_bg2.top + bmp_btn_bg.getHeight() + 30;
		rect_btn_bg2.right -= 80;

		rect_btn_bg3 = new RectF(rect_btn_bg2);
		rect_btn_bg3.top += 80;
		rect_btn_bg3.left += 80;
		rect_btn_bg3.bottom += 80;
		rect_btn_bg3.right += 80;
		
		rect_btn_exit = new RectF(rect_btn_bg3);
		rect_btn_exit.top -= 80;
		rect_btn_exit.left += 80;
		rect_btn_exit.bottom -= 80;
		rect_btn_exit.right += 80;
	}

	@Override
	public void initBimtap() {
		Resources res = getResources();
		bmp_main_bg = BitmapFactory.decodeResource(res, R.drawable.main_bg);
		bmp_btn_bg = BitmapFactory.decodeResource(res, R.drawable.btn_bg);
		bmp_btn_bg1 = BitmapFactory.decodeResource(res, R.drawable.btn_bg1);
		bmp_btn_bg2 = BitmapFactory.decodeResource(res, R.drawable.btn_bg2);
		bmp_btn_bg3 = BitmapFactory.decodeResource(res, R.drawable.btn_bg3);
		bmp_btn_bg4 = BitmapFactory.decodeResource(res, R.drawable.btn_bg2);
		
		bmp_btn_exit1= BitmapFactory.decodeResource(res, R.drawable.menu_word_exit1);
		bmp_btn_exit2= BitmapFactory.decodeResource(res, R.drawable.menu_word_exit2);
		bmp_btn_exit=bmp_btn_exit1;
		bmp_word_helper1 = BitmapFactory.decodeResource(res,
				R.drawable.word_help1);
		bmp_word_helper2 = BitmapFactory.decodeResource(res,
				R.drawable.word_help2);
		bmp_word_helper = bmp_word_helper1;

		bmp_word_about1 = BitmapFactory.decodeResource(res,
				R.drawable.word_about1);
		bmp_word_about2 = BitmapFactory.decodeResource(res,
				R.drawable.word_about2);
		bmp_word_about = bmp_word_about1;
		
		bmp_word_south1 = BitmapFactory.decodeResource(res,
				R.drawable.south_word1);
		bmp_word_south2 = BitmapFactory.decodeResource(res,
				R.drawable.south_word2);
		bmp_word_south = bmp_word_south1;

		bmp_word_guide1 = BitmapFactory.decodeResource(res,
				R.drawable.start_word1);
		bmp_word_guide2 = BitmapFactory.decodeResource(res,
				R.drawable.start_word2);
		bmp_word_guide = bmp_word_guide1;

	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);

		canvas.drawBitmap(bmp_main_bg, null, rect_main_bg, null);
		
		canvas.drawBitmap(bmp_btn_bg1, null, rect_btn_bg1, null);
		canvas.drawBitmap(bmp_btn_bg2, null, rect_btn_bg2, null);
		canvas.drawBitmap(bmp_btn_bg2, null, rect_btn_exit, null);
		canvas.drawBitmap(bmp_btn_bg3, null, rect_btn_bg3, null);
		canvas.drawBitmap(bmp_btn_bg4, null, rect_btn_bg4, null);
		
		canvas.drawBitmap(bmp_word_guide, null, rect_btn_bg1, null);
		canvas.drawBitmap(bmp_word_helper, null, rect_btn_bg2, null);
		canvas.drawBitmap(bmp_btn_exit, null, rect_btn_exit, null);
		canvas.drawBitmap(bmp_word_about, null, rect_btn_bg3, null);
		canvas.drawBitmap(bmp_word_south, null, rect_btn_bg4, null);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// 获取屏幕坐标
		int _x = (int) event.getX();
		int _y = (int) event.getY();
		if (event.getAction() == MotionEvent.ACTION_DOWN) {

			if (rect_btn_bg1.contains(_x, _y)) {
				bmp_word_guide = bmp_word_guide2;
			}

			else if (rect_btn_bg2.contains(_x, _y)) {
				bmp_word_helper = bmp_word_helper2;
			}

			else if (rect_btn_bg3.contains(_x, _y)) {
				bmp_word_about = bmp_word_about2;
			}
			else if (rect_btn_exit.contains(_x, _y)) {
				bmp_btn_exit = bmp_btn_exit2;
			}
			else if (rect_btn_bg4.contains(_x, _y)) {
				bmp_word_south = bmp_word_south2;
			}

		} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
			if (!rect_btn_bg1.contains(_x, _y)) {
				bmp_word_guide = bmp_word_guide1;
			}

			if (!rect_btn_bg2.contains(_x, _y)) {
				bmp_word_helper = bmp_word_helper1;
			}

			if (!rect_btn_bg3.contains(_x, _y)) {
				bmp_word_about = bmp_word_about1;
			}
			if (!rect_btn_exit.contains(_x, _y)) {
				bmp_btn_exit = bmp_btn_exit1;
			}
			if (!rect_btn_bg4.contains(_x, _y)) {
				bmp_word_south = bmp_word_south1;
			}

		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			if (rect_btn_bg1.contains(_x, _y)) {
				bmp_word_guide = bmp_word_guide1;
				father.gotoActivity(father, WebMapActivity.class);
			}

			if (rect_btn_bg2.contains(_x, _y)) {
				bmp_word_helper = bmp_word_helper1;
				father.gotoActivity(father, HelperActivity.class);
			}

			if (rect_btn_bg3.contains(_x, _y)) {
				bmp_word_about = bmp_word_about1;
				father.gotoActivity(father, AboutActivity.class);
			}if (rect_btn_bg4.contains(_x, _y)) {
				bmp_word_south = bmp_word_south1;
				father.gotoActivity(father, DirectionActivity.class);
			}
			if (rect_btn_exit.contains(_x, _y)) {
				bmp_btn_exit = bmp_btn_exit1;
				
				father.exitDialog();
			}
		}

		return true;
	}
}
